﻿using DiyEFConfigurationBuilder;
using DiyEFConfigurationBuilder.Enums;
using System;
using System.Threading;

namespace DiyEFConfiguration
{
    internal class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Hello, World!");
            string conn = "Server=localhost;port=3306;Database=diyefconfigdb;uid=root;pwd=qwer123456;Character Set=utf8;";
            // 未初始化时  EFConfiguration为空
            var uninitedConfiguration = EFConfigurationBuilder.EFConfiguration;
            // 初始化之后返回 IConfiguration对象
            var configuration = EFConfigurationBuilder.Init(conn, DbType.MySql, out string erroMesg);
            // 使用GetSection方法获取对应的键值对
            var value = configuration.GetSection("Connection").Value;
            // 初始化之后的 IConfiguration对象
            var initedConfiguration = EFConfigurationBuilder.EFConfiguration;
            // 连接对象
            var connectionStr = EFConfigurationBuilder.ConnectionStr;

            DiyConfig diyConfig = new DiyConfig()
            {
                Key = "diy",
                Value = "testDiy"
            };
            (bool result, string errorMesg) = EFConfigurationBuilder.CreateConfig(diyConfig);

            // 等待实体监控事件刷新配置
            Thread.Sleep(5*1000);

            // 测试数据
            var value2 = EFConfigurationBuilder.EFConfiguration.GetSection("diy").Value;
            var test = EFConfigurationBuilder.EFConfiguration.GetSection("Test").Value;
            var data = EFConfigurationBuilder.EFConfiguration.GetSection("data").Value;
            var trainLines = EFConfigurationBuilder.EFConfiguration.GetSection("data:trainLines").Value;
            var trainLines2 = EFConfigurationBuilder.EFConfiguration.GetSection("data").GetSection("trainLines").Value;
            var msg = EFConfigurationBuilder.EFConfiguration.GetSection("msg").Value;
            var success = EFConfigurationBuilder.EFConfiguration.GetSection("success").Value;

            var value3 = EFConfigurationBuilder.EFConfiguration.GetSection("Connection1").GetSection("Connection1").Value;
            var value4 = EFConfigurationBuilder.EFConfiguration.GetSection("Connection1").Value;
            var value5 = EFConfigurationBuilder.EFConfiguration.GetSection("Connection2").Value;
            Console.ReadLine();
        }
    }
}
